﻿using System;
using Microsoft.DirectX.DirectSound;

namespace Talk.Net.Library
{
	public class FormatManager
	{
		private static short channels = 2;
		private static short bitsPerSample = 16;

		// 11KHz use 11025 , 22KHz use 22050, 44KHz use 44100, etc.
		// speex likes 8, 16, 24 apparently
		private static int samplesPerSecond = 44100;

		public static int BytesPerSecond
		{
			get
			{
				return samplesPerSecond *  (int) ((short)(channels * (bitsPerSample / (short)8)));
			}
		}

		public static int SamplesPerSecond
		{
			get
			{
				return samplesPerSecond;
			}
		}

		public static WaveFormat GetFormat()
		{
			WaveFormat format = new WaveFormat();
			format.BitsPerSample = bitsPerSample;
			format.Channels = channels;
			format.BlockAlign = (short)(channels * (bitsPerSample / (short)8));
			format.FormatTag = WaveFormatTag.Pcm;
			format.SamplesPerSecond = samplesPerSecond;
			format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign;

			return format;
		}
	}
}
